package com.example.myapplication

import android.content.res.Configuration
import android.os.Message
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Shapes
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.myapplication.ui.theme.MyApplicationTheme

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier.fillMaxSize()) {
    Row(modifier = modifier.padding(all = 15.dp)) {
        val imageModifier = Modifier
            .size(40.dp)
            .clip(CircleShape)
            .border(1.5.dp, MaterialTheme.colorScheme.secondary, CircleShape)
        Image(
            contentScale = ContentScale.FillBounds,
            modifier = imageModifier,
            painter = painterResource(R.drawable.yang),
            contentDescription = "Contact profile picture",
        )
        Spacer(modifier = Modifier.width(12.dp))
        var isExpanded by remember { mutableStateOf(false) }
        Column(modifier = Modifier.clickable { isExpanded = !isExpanded }) {
            Text(
                text = "猪猪侠",
                color = MaterialTheme.colorScheme.secondaryContainer,
                style = MaterialTheme.typography.titleMedium
            )
            Spacer(modifier = Modifier.height(3.dp))
            Surface(shape = MaterialTheme.shapes.medium, color = MaterialTheme.colorScheme.inverseOnSurface) {
                Text(
                    text = "$name 什么",
                    style = MaterialTheme.typography.bodyMedium
                )
            }
            Surface(modifier = Modifier.shadow(1.dp, shape = MaterialTheme.shapes.medium)
            ,shape = MaterialTheme.shapes.medium) {
                Text(
                    text = "一个人$name",
                    style = MaterialTheme.typography.bodyMedium
                )
            }
//            Surface(
//                color = MaterialTheme.colorScheme.primary,
//                shape = RoundedCornerShape(9.dp),
//                modifier = Modifier.padding(5.dp)
//            ) {
//                Text(
//                    text = "Hello, Compose!",
//                    style = MaterialTheme.typography.bodyLarge,
//                    modifier = Modifier.padding(16.dp)
//                )
//            }
        }

    }
}

//@Preview(
////    uiMode = Configuration.UI_MODE_NIGHT_YES,
//    showBackground = true,
//    name = "Dark Mode")
//@Composable
//fun GreetingPreview() {
//    MyApplicationTheme {
//        Greeting("飞猪侠", Modifier.fillMaxSize())
//    }
//}

@Composable
fun Conversation() {
    val itemsList = (1..100).toList()
    val stringList = itemsList.map { it.toString() }
    LazyColumn {
        items(stringList) { message ->
            Greeting(message, Modifier.fillMaxSize())
        }
    }
}

@Preview()
@Composable
fun PreviewConversation() {
    Conversation()
}
